package fr.polichouz.geotracer.corelocator.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import fr.polichouz.geotracer.shared.GeotracerService;
import fr.polichouz.geotracer.corelocator.GeotracerServiceServerImpl;
import fr.polichouz.geotracer.shared.SimpleLocation;

@SuppressWarnings("serial")
public class UpdateLocationServlet extends HttpServlet {

    /** Geotracer service. */
    private GeotracerService service;

    /**
     * Default constructor.
     */
    public UpdateLocationServlet() {
	super();
	service = GeotracerServiceServerImpl.get();
    }

    

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

	// Get posted informations.
	String username = req.getParameter("username");
	String password = req.getParameter("password");
	Double lattitude = Double.parseDouble(req.getParameter("lattitude"));
	Double longitude = Double.parseDouble(req.getParameter("longitude"));

	// Call the service.
	service.updateLocation(new SimpleLocation(lattitude, longitude), 
		username, password);
	
	super.doPost(req, resp);
    }


}
